/*
	obj:
		method:get post
		url:01-test.php?age=19
		async
		data:{username:"wwww"} 变成 01-test.php?username=wwww&age= 19
		success:回调函数
		//encodeURIComponent
*/
function ajaxFunc(obj)
{
	var xhr = new XMLHttpRequest();
	obj.data = (function(data){
		var tmp = [];
		for(var key in data){
			tmp.push(encodeURIComponent(key)) + '=' + encodeURIComponent((data[key]));

		};
		return tmp.join('&');
	})(obj.data);

	if(obj.method == 'get'){
		if(obj.url.indexOf('?') == -1){
			obj.url += '?' + obj.data;
		}else{
			obj.url += '&' + obj.data;
		}
	}
	xhr.open(obj.method,obj.url,obj.async);
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 || xhr.status ==200){
			obj.success(xhr.responseText);
		}
	}
	if(obj.method == 'post')
	{
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send(obj.data);
	}else{
		xhr.send(null);
	}
}